package edu.ynmd.parm.action;

import edu.ynmd.parm.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
public class PublicAction {


    @RequestMapping("getAnServerString")
    @ResponseBody
    public String getAnServerString(){

        return "服务器端返回的字符串";
    }

    //http://localhost/getParmValue?sid=abc123
    @GetMapping("getParmValue")
    @ResponseBody
    public String getParmValue(@RequestParam String sid){
        return sid+"服务器已收到";
    }

    //http://localhost/getPathValue/def456
    @GetMapping("getPathValue/{sid}")
    @ResponseBody
    public String getPathValue(@PathVariable(name="sid") String sid){

        return  sid+"服务器已收到";
    }


    @PostMapping("receiveAnValue")
    @ResponseBody
    public Student receiveAnObject(@RequestBody Student student){
        return student;
    }

    //form 表单提交的参数接收
    @PostMapping("receiveAnFormValue")
    @ResponseBody
    public Student receiveAnFormValue (Student student){
        return student;
    }

    @GetMapping("returnAnListObject")
    @ResponseBody
    public List<Student> returnAnListValue(){
        List<Student> s1=new ArrayList<>();
        for (int i=0;i<10;i++){
            Student s=new Student();
            s.setId("id"+i);
            s.setStunum("stunum"+i);
            s.setName("name"+i);
            s1.add(s);
        }
        return s1;
    }

    @PostMapping("receiveAnListObject")
    @ResponseBody
    public List<Student> receiveAnListObject(@RequestBody List<Student> s1){
        return s1;
    }
}
